﻿@using SmartCode
@using SmartCode.Db
@model BuildContext
@{
    var project = Model.Project;
    var dbSource = Model.GetDataSource<DbSource>();
    var table = Model.GetCurrentTable();
    var pkCol = table.PKColumn;
    var prefix = dbSource.DbProvider.ParameterPrefix;
    var notEqCols = table.Columns.Where(m => m.ConvertedName != m.Name);
    var resultMapName = $"{table.ConvertedName}ResultMap";
    var queryStatementResultMap = table.HasColNameNotEqConvertedName ? $"ResultMap=\"{resultMapName}\"" : "";
}

<!--获取表映射实体-->
<Statement Id="GetEntity" @(queryStatementResultMap)>
    Select 
    <Include RefId="AllCols"/>
    From @table.Name As T
    <Where Min="1">
        @foreach (var col in table.Columns)
        {
            <IsNotEmpty Prepend="And" Property="@col.ConvertedName">
                T.@col.Name= @($"{prefix}{col.ConvertedName}")
            </IsNotEmpty>
        }
    </Where>
    Limit 1
</Statement>